package system

import (
	midd "a-admin/web/middleware"

	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/monitor"
)

const bastApi = "/system"

func InitSystemRoutes(r fiber.Router) {
	r.Get("/dashboard", monitor.New()) // 应用监控
	// 公共接口
	commServer := NewSysCommController()
	r.Get("/comm/download/:filename", commServer.Download)
	r.Post("/comm/upload", commServer.Upload)

	// 登录接口
	loginServer := NewSysLoginController()
	r.Post("/login", loginServer.Login)
	r.Get("/captchaImage", loginServer.CaptchaImage)
	r.Post("/logout/:tk", loginServer.LoginOut)
	r.Get("/captchaVerify", loginServer.CaptchaVerify)
	r.Get("/getEmailCode", loginServer.GetEmailCode)
	r.Get("/emailCodeVerify", loginServer.EmailCodeVerify)
	r.Post("/register", loginServer.Register)
	r.Get(bastApi+"/getInfo", loginServer.GetInfo)
	r.Get(bastApi+"/getRouters", loginServer.GetRouters)

	// 登录信息接口
	logininforServer := NewSysLogininforController()
	r.Get(bastApi+"/logininfor/rows", logininforServer.List)
	r.Post(bastApi+"/logininfor/quit/:tokens", midd.OperLogHandler("SYS", midd.FORCE), logininforServer.Quit)
	r.Post(bastApi+"/logininfor/unlock/:names", midd.OperLogHandler("SYS", midd.OTHER), logininforServer.Unlock)
	r.Post(bastApi+"/logininfor/export", midd.OperLogHandler("SYS", midd.EXPORT), logininforServer.Export)
	r.Post(bastApi+"/logininfor/clear", midd.OperLogHandler("SYS", midd.CLEAN), logininforServer.Clear)

	// 部门接口
	deptServer := NewSysDeptController()
	r.Get(bastApi+"/dept/rows", deptServer.List)
	r.Get(bastApi+"/dept/get/:id", deptServer.Get)
	r.Post(bastApi+"/dept/del/:ids", deptServer.Del)
	r.Post(bastApi+"/dept/add", deptServer.Add)
	r.Post(bastApi+"/dept/edit", deptServer.Edit)

	r.Get(bastApi+"/dept/rows/exclude/:id", deptServer.ExcludeChild)
	r.Get(bastApi+"/dept/getTree", deptServer.GetTree)
	r.Get(bastApi+"/dept/getTreeSelect", deptServer.GetTreeSelect)

	// 菜单接口
	menuServer := NewSysMenuController()
	r.Get(bastApi+"/menu/rows", menuServer.List)
	r.Get(bastApi+"/menu/get/:id", midd.PermsHandler("system:menu:query"), menuServer.Get)
	r.Post(bastApi+"/menu/del/:ids", midd.PermsHandler("system:menu:remove"), menuServer.Del)
	r.Post(bastApi+"/menu/add", midd.PermsHandler("system:menu:add"), menuServer.Add)
	r.Post(bastApi+"/menu/edit", midd.PermsHandler("system:menu:edit"), menuServer.Edit)

	r.Get(bastApi+"/menu/treeselect", midd.PermsHandler("system:menu:query"), menuServer.GetTree)
	r.Get(bastApi+"/menu/getTree", menuServer.GetTree)
	r.Get(bastApi+"/menu/getTreeSelect", menuServer.GetTreeSelect)
	r.Get(bastApi+"/menu/roleMenuTreeselect/:id", menuServer.RoleMenuTreeSelect)

	// 通知公告接口
	noticeServer := NewSysNoticeController()
	r.Get(bastApi+"/notice/rows", noticeServer.List)
	r.Get(bastApi+"/notice/get/:id", noticeServer.Get)
	r.Post(bastApi+"/notice/del/:ids", noticeServer.Del)
	r.Post(bastApi+"/notice/add", noticeServer.Add)
	r.Post(bastApi+"/notice/edit", noticeServer.Edit)

	r.Post(bastApi+"/notice/onRead/:id", noticeServer.OnRead)

	// 操作日志接口
	operlogServer := NewSysOperlogController()
	r.Get(bastApi+"/operlog/rows", operlogServer.List)
	r.Post(bastApi+"/operlog/export", operlogServer.Export)
	r.Post(bastApi+"/operlog/clear", operlogServer.Clear)

	// 岗位接口
	postServer := NewSysPostController()
	r.Get(bastApi+"/post/rows", postServer.List)
	r.Get(bastApi+"/post/get/:id", postServer.Get)
	r.Post(bastApi+"/post/del/:ids", postServer.Del)
	r.Post(bastApi+"/post/add", postServer.Add)
	r.Post(bastApi+"/post/edit", postServer.Edit)
	r.Post(bastApi+"/post/export", postServer.Export)

	// 角色接口
	roleServer := NewSysRoleController()
	r.Get(bastApi+"/role/rows", midd.PermsHandler("system:role:list"), roleServer.List)
	r.Get(bastApi+"/role/get/:id", roleServer.Get)
	r.Post(bastApi+"/role/del/:ids", roleServer.Del)
	r.Post(bastApi+"/role/add", roleServer.Add)
	r.Post(bastApi+"/role/edit", roleServer.Edit)
	r.Post(bastApi+"/role/export", roleServer.Export)

	r.Get(bastApi+"/role/deptTree/:id", midd.PermsHandler("system:role:list"), roleServer.DeptTree)
	r.Post(bastApi+"/role/changeStatus", roleServer.ChangeStatus)
	r.Post(bastApi+"/role/dataScope", roleServer.DataScope)
	r.Post(bastApi+"/role/editAndMenu", roleServer.EditAndMenu)
	r.Post(bastApi+"/role/editAndDept", roleServer.EditAndDept)
	r.Get(bastApi+"/role/authUser/allocatedList", midd.PermsHandler("system:role:list"), roleServer.AllocatedList)
	r.Get(bastApi+"/role/authUser/unallocatedList", midd.PermsHandler("system:role:list"), roleServer.UnallocatedList)
	r.Post(bastApi+"/role/authUser/selectAll", midd.PermsHandler("system:role:edit"), roleServer.SelectAll)
	r.Post(bastApi+"/role/authUser/cancel", midd.PermsHandler("system:role:edit"), roleServer.Cancel)
	r.Post(bastApi+"/role/authUser/cancelAll", midd.PermsHandler("system:role:edit"), roleServer.CancelAll)

	// 用户接口
	userServer := NewSysUserController()
	r.Get("/profile/avatar/*", userServer.GetAvatar)
	r.Get(bastApi+"/user/rows", midd.PermsHandler("system:user:list"), userServer.List)
	r.Get(bastApi+"/user/get/:id", midd.PermsHandler("system:user:query"), userServer.Get)
	r.Post(bastApi+"/user/del/:ids", midd.PermsHandler("system:user:remove"), midd.OperLogHandler("SYS", midd.DELETE), userServer.Del)
	r.Post(bastApi+"/user/add", midd.PermsHandler("system:user:add"), midd.OperLogHandler("SYS", midd.UPDATE), userServer.Add)
	r.Post(bastApi+"/user/edit", midd.PermsHandler("system:user:edit"), midd.OperLogHandler("SYS", midd.UPDATE), userServer.Edit)
	r.Post(bastApi+"/user/export", midd.PermsHandler("system:user:export"), midd.OperLogHandler("SYS", midd.EXPORT), userServer.Export)

	r.Get(bastApi+"/user/profile/get", userServer.Profile)
	r.Post(bastApi+"/user/profile/edit", midd.OperLogHandler("SYS", midd.UPDATE), userServer.Edit)
	r.Post(bastApi+"/user/profile/updatePwd", midd.OperLogHandler("SYS", midd.UPDATE), userServer.UpdatePwd)
	r.Post(bastApi+"/user/profile/avatar", userServer.Avatar)

	r.Get(bastApi+"/user/getSelectList", userServer.GetSelectList)
	r.Get(bastApi+"/user/deptTree", midd.PermsHandler("system:user:list"), userServer.DeptTree)
	r.Get(bastApi+"/user/authRole/:id", midd.PermsHandler("system:user:query"), userServer.AuthRole)
	r.Post(bastApi+"/user/importTemplate", userServer.ImportTemplate)
	r.Post(bastApi+"/user/importData", midd.PermsHandler("system:user:import"), midd.OperLogHandler("SYS", midd.IMPORT), userServer.ImportData)
	r.Post(bastApi+"/user/changeStatus", midd.PermsHandler("system:user:edit"), midd.OperLogHandler("SYS", midd.UPDATE), userServer.ChangeStatus)
	r.Post(bastApi+"/user/resetPwd", midd.PermsHandler("system:user:edit"), midd.OperLogHandler("SYS", midd.UPDATE), userServer.ResetPwd)
	r.Post(bastApi+"/user/authRole", midd.PermsHandler("system:user:edit"), midd.OperLogHandler("SYS", midd.UPDATE), userServer.InsertAuthRole)

}
